{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
module Maing where
import Data.Text(Text)
import qualified Data.Text as T
import Text.Hamlet(HtmlUrlI18n,ihamlet,shamlet,hamlet,HtmlUrl)
import Text.Blaze.Html (toHtml,Html)
import Text.Blaze.Html.Renderer.String(renderHtml)


data MyRoute = Home | Time | Stylesheet

renderUrl :: MyRoute -> [(Text,Text)]->Text
renderUrl Home _ = "/home"
renderUrl Time _ = "/time"
renderUrl Stylesheet _ = "/style.css"

renderUrl1 :: Language -> [(Text,Text)]->Text
renderUrl1 Chinese _ = "/home"
renderUrl1 English _ = "/time"

data Msg = Hello | Apples Int
data Language = Chinese|English

renderEnglish :: Msg->Text
renderEnglish Hello = "Hello"
renderEnglish (Apples 0) = "You did not buy any apples"
renderEnglish (Apples 1) = "You bought 1 apples"
renderEnglish (Apples i) = T.concat ["You bought",T.pack $ show i ," apples."]

renderLanguage::Msg->Html
renderLanguage Hello = [hamlet|<label>@{Chinese}|] renderUrl1
renderLanguage (Apples _) = [hamlet|<label>@{English}|] renderUrl1

renderChinese::Msg->Html
renderChinese Hello = [shamlet|<lable>NiHao|]
renderChinese (Apples i)=[shamlet|<lable>Ni you #{i} ge pingguo.|]

template :: Int -> HtmlUrlI18n Msg Language
template count =[ihamlet|
$doctype 5
<html>
    <head>
        <title>i18n
    <body>
        <h3><label>@{Chinese}
        <h1>_{Hello}
        <p>_{Apples count}
|]

main :: IO()
{-
main = putStrLn $ renderHtml
        $(template 5) (toHtml.renderEnglish) renderUrl
-}
{-
main = putStrLn $ renderHtml
        $(template 5) renderChinese renderUrl

-}
main = putStrLn $ renderHtml $(template 5) renderLanguage renderUrl1








